package com.example.expandablelistview.multimedia;

import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;
import android.media.SoundPool.OnLoadCompleteListener;
import android.os.Bundle;
import android.view.View;

import com.example.expandablelistview.R;

public class SoundPoolTest extends Activity {
	SoundPool mPool;
	int dingdong;
	int stream;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mul_soundpooltest);
		mPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
		dingdong = mPool.load(this, R.raw.dingdong, 1);
	}
	
	SoundPool.OnLoadCompleteListener mListener = new OnLoadCompleteListener() {
		public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
			if (status==0){
				stream = soundPool.play(sampleId,1,1,0,0,1);
			}
		}
	};
	
	public void mOnClick(View v){
		MediaPlayer mPlayer;
		switch(v.getId()){
		case R.id.play1://보통재생
			mPool.play(dingdong, 1, 1, 0, 0, 1);
			break;
		case R.id.play2://볼륨의 절반재생
			mPool.play(dingdong, 0.5f, 0.5f, 0, 0, 1);
			break;
		case R.id.play3://3회반복
			mPool.play(dingdong, 1, 1, 0, 2, 1);
			break;
		case R.id.play4://1/2배속 재생
			mPool.play(dingdong, 1, 1, 0, 0, 0.5f);
			break;
			
		case R.id.play5://바로 재생
			dingdong = mPool.load(this, R.raw.goodtime, 1);
			mPool.play(dingdong, 1, 1, 0, 0, 1);
			break;
		case R.id.play6://로드 완료 후 재생
			mPool.setOnLoadCompleteListener(mListener);
			mPool.load(this, R.raw.goodtime, 1);
			break;
		case R.id.play7://잠시 멈춤
			mPool.autoPause();
			break;
		case R.id.play8://멈춘위치에서 재생
			mPool.autoResume();
			break;
		}
	}
	
}
